package com.atguigu.lease.common.exception;

import com.atguigu.lease.common.result.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.io.IOException;
import java.sql.SQLException;

//@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {

    //@ExceptionHandler 表示哪些异常此方法需要处理
    @ExceptionHandler(value = {Exception.class })
    public Result handleException(Exception ex){
        ex.printStackTrace();
        //log.error(ex.getMessage());
        return Result.fail();
    }

    @ExceptionHandler(value = {LeaseException.class })
    public Result handleLeaseException(LeaseException ex){
        ex.printStackTrace();
        return Result.fail(ex.getCode(),ex.getMessage());
    }

}
